#include <iostream>
#include <string>
#include <stack>
#include <unordered_map>

bool is_valid_sequence(const std::string& sequence) {
    std::unordered_map<char, char> matching_brackets = {{')', '('}, {']', '['}, {'}', '{'}, {'>', '<'}};
    std::stack<char> a;
    for (char bracket : sequence) {
        if (bracket == '(' || bracket == '{' || bracket == '[' || bracket == '<') {
            a.push(bracket);
        } else if (bracket == ')' || bracket == '}' || bracket == ']' || bracket == '>') {
            if (a.empty() || a.top() != matching_brackets[bracket]) {
                return false;
            }
            a.pop();
        } else {
            return false;
        }
    }
    return a.empty();
}

int main() {
    std::string sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> sequence;
    std::cout << std::boolalpha << is_valid_sequence(sequence) << std::endl;
    return 0;
}
